/**
 * WTF Engine
 * 
 * License... etc.
 **
 * Particle effects base class
 * Used for decorative effects only.
 **
 * Authors: Sean Micklethwaite
 */

#ifndef __fx_particleH__
#define __fx_particleH__

#include "animation.h"
#include "physics.h"

namespace WtfEngine {
	/**
	 * Effects particle base class.
	 * Used for decoration only, thus given lowest network priority.
	 **/
	class FxParticle: public virtual IDynamic, public Physical {
		tGameTime	mLife;

		public:
			typedef struct FxParticleCreationOptions: public Physical::tCreationOptions {
				WtfGraphics::GraphicsData::tCacheRef rGraphicsData;
				tGameTime						Life;
				tPosition						vPosition;
				tDirection						vVelocity;
				tScalar							Mass;

				FxParticleCreationOptions(const WtfGraphics::GraphicsData::tCacheRef& data, tScalar life,
					const tVector& vInitPos = tVector(), const tPosition& initVel = tPosition(), tScalar mass = 0.02):
				rGraphicsData(data), Life(life), vPosition(vInitPos), vVelocity(initVel), Mass(mass) {};
			} tCreationOptions;

			FxParticle(const tCreationOptions& options);
			virtual ~FxParticle();

			void			Update();
			virtual void	Update(tGameTime dt);

			virtual void	Destroy();
	};

	/**
	 * Emits streams of particles
	 **/
	class FxParticleGenerator: public Animation {
		public:
			typedef struct ParticleGeneratorOptions {
				tGameTime	GeneratorLife;
				tGameTime	ParticleLife;
				tGameTime	ParticleInterval;

				tPosition	vPosition;
				tDirection	vDirection;
				tScalar		Speed;
				tScalar		Mass;

				Functor::tRef	rGeneratorFunc;

				tScalar		RandomComponentOfLife; // hehe
				tScalar		RandomComponentOfInterval;
				tScalar		RandomComponentOfDirection;
				tScalar		RandomComponentOfSpeed;


 				ParticleGeneratorOptions(tGameTime generatorLife = -1, tGameTime particleLife = 1.0, tGameTime particleInterval = 0.1,
					const tPosition& position = tPosition(), const tDirection& direction = tDirection(), tScalar mass = 0.02,
					tScalar randomLife = 0, tScalar randomInterval = 0, tScalar randomDirection = 0, tScalar randomSpeed = 0):
				GeneratorLife(generatorLife), ParticleLife(particleLife), ParticleInterval(particleInterval), vDirection(direction.normalize()),
					Speed(direction.length()), Mass(mass), RandomComponentOfLife(randomLife), RandomComponentOfInterval(randomInterval),
					RandomComponentOfDirection(randomDirection), RandomComponentOfSpeed(randomSpeed) {};
			} tInitOptions;

		private:
			tInitOptions	mOptions;

			tGameTime	mParticleTimer;

		public:
			FxParticleGenerator();
			virtual ~FxParticleGenerator();

			void Init(const tInitOptions& options);

			/// Default particle generator function - generates a basic particle
			/// with the specified graphical representation
			void GenerateParticle(const WtfGraphics::GraphicsData::tCacheRef& data);

			virtual void Update(tGameTime dt);

			virtual void Destroy();

			GC_AUTOSIZE(FxParticleGenerator);
	};
};

#endif
